-- doping
-- create by wangy
-- 兴奋剂

return {
    apply = function(source, target, skillId, round, para, extra)
        local effectRound = -1;
        if para[2] > 0 then
            effectRound = round + para[2] + 1;
        end

        local hp     = target:queryAttrib("hp");
        local max_hp = target:queryAttrib("max_hp");
        local count  = math.modf(max_hp * 5 / 100);

        -- 扣除到1点
        if count >= hp then
            count = hp - 1;
        end

        -- 增加命中动作、伤害
        if count > 0 then
            SkillM.getSequence(target):hit(source, target, skillId);
            CombatM.receiveDamage(source, target, count, skillId, extra);
        end

        -- 根据专属等级计算状态数值
        local prop = PropM.combine(source, "doping", 60);
        local level = PropM.apply(prop, 0);

        local value = 50;
        local damageReduce = 0;
        if level >= 5 then
            value = value + 100;
        end
        if level >= 4 then
            damageReduce = damageReduce + 300;
        end
        if level >= 3 then
            value = value + 50;
        end
        if level >= 2 then
            damageReduce = damageReduce + 200;
        end

        -- 加成
        if type(extra) == "table" and extra.propertyId then
            prop = PropM.combine(source, "property_damage2", extra.propertyId);
            if prop[3] > 0 then
                value = value + PropM.apply(prop, value);
            end
        end

        -- 状态
        local condition = {
            ["value"] = value,
            ["end_round"] = effectRound,
        };
        if damageReduce > 0 then
            condition["damage_reduce"] = damageReduce;
        end

        -- 附加状态
        CombatStatusM.applyStatus(target, "doping", condition);

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
};
